local Clock={
	["start"]=GetTime(),["time"]=0,["12"]=0,["24"]=0,
	["hour"]=0,["mins"]=0,["_hour"]=0,["_mins"]=0,
	["clock"]="",["date"]="",["game"]="",["total"]="",
	["update"]=0,
};
 
function XBarClock_OnEvent(this,event)
-- ChatFrame1:AddMessage("XBar-Clock : "..event);
	if (event=="LOADING_END") then this.date=0; end
end

function XBarClock_OnUpdate(this,elapsedTime)
	Clock["update"]=Clock["update"]+elapsedTime;
	if (Clock["update"]>=1) then -- count every second
		Clock["update"]=0;
		if (this.starting) then
			this.remaining=this.remaining-elapsedTime;
			if (this.remaining>0) then XBarClock_SetTime(this,this.duration,this.remaining);
			else this.starting=nil; end
		else XBarClock_SetTime(this,60,60-tonumber(os.date("%S"))); end
		Clock["time"]=GetTime()-Clock["start"];
		Clock["_hour"]=string.format("%02d",Clock["hour"]);
		Clock["hour"]=math.floor(Clock["time"]/3600);
		Clock["_mins"]=string.format("%02d",Clock["mins"]);
		Clock["mins"]=((Clock["time"]-(Clock["hour"]*3600))/60);
		if (Clock["_mins"]<string.format("%02d",Clock["mins"])) then XBar["PlayedMins"]=XBar["PlayedMins"]+1; end
		if (XBar["PlayedMins"]>59) then XBar["PlayedHour"]=XBar["PlayedHour"]+1; XBar["PlayedMins"]=0; end
		if (Clock["_hour"]<string.format("%02d",Clock["hour"])) then XBar["PlayedHour"]=XBar["PlayedHour"]+1; end
		if (XBar["PlayedHour"]>23) then XBar["PlayedDays"]=XBar["PlayedDays"]+1; XBar["PlayedHour"]=0; end
		Clock["12"]=os.date("|cff7676FC%I:%M.%S|r |cff767676%p|r");
		Clock["24"]=os.date("|cff7676FC%H:%M.%S|r |cff767676|r");
		Clock["date"]="|cffA3A3FC"..os.date("%d.%m.%y").."|r";
		Clock["game"]=string.format("|cff7676FC%02d:%02d|r",Clock["hour"],Clock["mins"]);
		Clock["total"]=string.format("|cff7676FC%d|r |cff767676Days|r |cff7676FC%02d:%02d|r",XBar["PlayedDays"],XBar["PlayedHour"],XBar["PlayedMins"]);
	-- Output
		local usrtxt={[1]=XBar["ClockV1"],[2]=XBar["ClockV2"],[3]=XBar["ClockV3"],[4]=XBar["ClockV4"],[5]=XBar["ClockV5"]};
		local output="";
		for i=1,5 do
			usrtxt[i],_=XBar_StrReplace(usrtxt[i],"%[TIME24%]",Clock["24"]);
			usrtxt[i],_=XBar_StrReplace(usrtxt[i],"%[TIME12%]",Clock["12"]);
			usrtxt[i],_=XBar_StrReplace(usrtxt[i],"%[DATE%]",Clock["date"]);
			usrtxt[i],_=XBar_StrReplace(usrtxt[i],"%[ONLINE%]",Clock["game"]);
			usrtxt[i],_=XBar_StrReplace(usrtxt[i],"%[TOTALONLINE%]",Clock["total"]);
		end
		if (XBar["ClockT1"]==true) then
			if (this.date==1) then output=usrtxt[3]; elseif (this.clock==12) then output=usrtxt[2]; else output=usrtxt[1]; end
		end
		if (XBar["ClockT2"]==true) then
			if (this.game==1) then if (XBar["ClockT1"]==true) then output=output.."\n"..usrtxt[5]; else output=usrtxt[5]; end
			else if (XBar["ClockT1"]==true) then output=output.."\n"..usrtxt[4]; else output=usrtxt[4]; end; end
		end
		XBarClock_F_Text:SetText(output);
	-- EoL
	end
end

function XBarClock_OnClick(key,this)
	if (key=="RBUTTON") then if (this.date==1) then this.date=0; else this.date=1; end
	elseif (key=="LBUTTON" and IsShiftKeyDown()) then if (this.game==1) then this.game=0; else this.game=1; end
	elseif (key=="LBUTTON") then if (this.clock==12) then this.clock=24; else this.clock=12; end; end
end

function XBarClock_SetTime(this,duration,remaining)
	if (duration>0 and remaining>0) then
		XBarClock_B_Icon:SetCooldown(duration,remaining);
		this.starting=1; this.duration=duration; this.remaining=remaining;
	end
end

function aMap_OnMouseWheel(delta)

	local wmfa = WorldMapViewFrame_WorldMapTexture_1:GetAlpha(), WorldMapViewFrame_WorldMapTexture_2:GetAlpha(), 
	WorldMapViewFrame_WorldMapTexture_3:GetAlpha(), WorldMapViewFrame_WorldMapTexture_4:GetAlpha(), 
	WorldMapViewFrame_WorldMapTexture_5:GetAlpha(), WorldMapViewFrame_WorldMapTexture_6:GetAlpha(), 
	WorldMapViewFrame_WorldMapTexture_7:GetAlpha(), WorldMapViewFrame_WorldMapTexture_8:GetAlpha(), 
	WorldMapViewFrame_WorldMapTexture_9:GetAlpha(), WorldMapViewFrame_WorldMapTexture_10:GetAlpha(), 
	WorldMapViewFrame_WorldMapTexture_11:GetAlpha(), WorldMapViewFrame_WorldMapTexture_12:GetAlpha(), 
	WorldMapOptionButton:GetAlpha(), WorldMapSelectMapButton:GetAlpha(), WorldMapBorderFrame:GetAlpha(), 
	WorldMapFrame_BottonRight:GetAlpha(), WorldMapFrame_BottonLeft:GetAlpha(), WorldMapFrame_TopRight:GetAlpha(), 
	WorldMapFrame_Bottom:GetAlpha(), WorldMapFrame_Middle:GetAlpha(), WorldMapFrame_Top:GetAlpha(), 
	WorldMapFrame_TopLeft:GetAlpha(), WorldMapFrame_Left:GetAlpha(), WorldMapFrame_Right:GetAlpha();
	if (delta >= 120) then
		wmfa = wmfa + 0.1;
		if wmfa > 1 then
			wmfa = 1;
			return;
		end
		DEFAULT_CHAT_FRAME:AddMessage("Set transparency of the map to "..string.format("%.1f",wmfa));
	else
		wmfa = wmfa - 0.1;
		if wmfa < 0.1 then
			wmfa = 0.1;
			return;
		end
		DEFAULT_CHAT_FRAME:AddMessage("Set transparency of the map to "..string.format("%.1f",wmfa));
	end
	
	WorldMapOptionButton:SetAlpha(wmfa);
	WorldMapSelectMapButton:SetAlpha(wmfa);
	WorldMapBorderFrame:SetAlpha(wmfa);
	WorldMapFrame_Bottom:SetAlpha(wmfa);
	WorldMapFrame_Middle:SetAlpha(wmfa);
	WorldMapFrame_Top:SetAlpha(wmfa);
	WorldMapFrame_Left:SetAlpha(wmfa);
	WorldMapFrame_Right:SetAlpha(wmfa);
	WorldMapFrame_TopLeft:SetAlpha(wmfa);
	WorldMapFrame_TopRight:SetAlpha(wmfa);
	WorldMapFrame_BottonLeft:SetAlpha(wmfa);
	WorldMapFrame_BottonRight:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_1:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_2:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_3:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_4:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_5:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_6:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_7:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_8:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_9:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_10:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_11:SetAlpha(wmfa);
	WorldMapViewFrame_WorldMapTexture_12:SetAlpha(wmfa);
end